<?php 
namespace PsiFramework\Classes\Util\Parameters\DAO;

import("Classes.Util.Parameters.DAO.ConfigDAO");
import("Classes.Util.Plugin");

use \PsiFramework\Classes\Util\Parameters\DAO\ConfigDAO;
use \PsiFramework\Classes\Util\Plugin;

/**
 * PsiFramework
 * Php Simple Framework
 *
 * @author Rémi San
 * @version beta
 */

/**
 * The PluginDAO class is the generic class to retrieve plugin parameters
 *
 * @package Util.Parameters.DAO
 */
class PluginDAO extends ConfigDAO
{

    protected /*string[]*/ $_dependenciesNames = array();

    public function getDependeciesNames()
    {
        return $this->_dependenciesNames ;
    }

    public function retrievePlugin()
    {

        $vars = $this->retrieve();

        //dependencies
        $dependencies = array();
        $dependenciesElement
            = $this->_racine
                ->getElementsByTagName("dependencies")->item(0);
        if (!is_null($dependenciesElement)) {
            $dependenciesElements
                = $dependenciesElement->getElementsByTagName(
                    "plugin-dependency"
                );
            foreach ($dependenciesElements as $dependecyElement) {
                $pluginName = $dependecyElement->getAttribute("name");
                $this->_dependenciesNames[] = $pluginName ;
            }
        }

        $plugin = new Plugin();
        $plugin->setName($vars['name']);
        $plugin->setDependencies($dependencies);
        $plugin->setActionMapping($vars['actionMapping']);
        $plugin->setServiceMapping($vars['servicesParameters']);
        $plugin->setParameters($vars['parameters']);
        $plugin->setObjectParameters($vars['objectParameters']);

        return $plugin ;
    }
}
